﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Helps;

namespace EF_Cord
{
    public class DbContextFactory
    {
        public static DbContext CreateContext()
        {


            DbContext dbContext = null;

            string dbType = AppConfigurtaionServices.Configuration["SqlType"];

            switch (dbType)
            {

                case "MySql":
                    dbContext = CreateMySQLContext();
                    break;
                case "Sql":
                    dbContext = CreateSqlContext();
                    break;
            }

            return dbContext;
        }
        /// <summary>
        /// 创建ORACLE Dbcontext
        /// </summary>
        /// <returns></returns>
        static DbContext CreateSqlContext()
        {

            DbContextOptions<SDBCountext> options = new DbContextOptions<SDBCountext>();
            SDBCountext sDBCountext = new SDBCountext(options);
            return sDBCountext;
        }


        /// <summary>
        /// 创建MySQL Dbcontext
        /// </summary>
        /// <returns></returns>
        static DbContext CreateMySQLContext()
        {

            DbContextOptions<MyDBCountext> options = new DbContextOptions<MyDBCountext>();
            MyDBCountext myDBCountext = new MyDBCountext(options);
            return myDBCountext;
        }
    }
}
